package src;

import junit.framework.TestCase;
import org.junit.Test;
import Data.CarDataModel;

public class ComputeRiskTest extends TestCase {
	private static final int SAFETY_VALUE = 10;
	@Test
	public void testCompute_data() {
		CarDataModel currentCar, frontCar;
		int rate, resultFromMethod, resultAbsolute, result;
		
		currentCar = new CarDataModel();
		frontCar = new CarDataModel();
		currentCar.distanceToFront = 40;
		currentCar.velocity = 30;
		frontCar.distanceToFront = 30;
		frontCar.velocity = 20;
		rate = 100;
		
		double minDistance;
		minDistance = (0.5 * currentCar.velocity) + 
						0.01 * (Math.pow(currentCar.velocity, 2) - Math.pow(frontCar.velocity, 2) ) ;
		assertEquals(20.0, minDistance);
//		minDistance = 15 + 0.01 * (900 - 400);
//		minDistance = 20;
		
		minDistance *= (double)rate * 0.01;
		assertEquals(20.0, minDistance);
//		minDistance = 20;
		
		minDistance += SAFETY_VALUE;
		assertEquals(30.0, minDistance);
//		minDistance = 20 + 10;
//		minDistance = 30;
		
		if(currentCar.distanceToFront * 0.4 > minDistance)
			result = 1; //Normal
		else if(currentCar.distanceToFront * 0.6 > minDistance)
			result = 2; // care
		else if(currentCar.distanceToFront * 0.9 > minDistance)
			result = 3; // wanning
		else
			result = 4;// danger
		
		resultAbsolute = 3;
		
		resultFromMethod = result;
		assertEquals(resultAbsolute, resultFromMethod);
	}
}
